<?php
namespace app\admin\controller;
use app\service\FileService;

class File extends Admin
{
    public function __construct(FileService $service)
    {
        parent::__construct();
        $this->service = $service;
    }
    public function index()
    {
        if (!$this->request->isPost()) {
            $this->assign("title","文件列表");
            $this->assign("module_list",json_encode(config("global.MODULE_MAPPING")));
            $this->assign("file_type",json_encode(config("global.FILE_UPLOAD_LIST")));
            return $this->fetch("index");
        }
        $params = $this->request->post();
        $where =[];
        if (!empty($params["module"])) {
            $where[]=["module","=",$params["module"]];
        }
        if (!empty($params["type"])) {
            $where[]=["type","=",$params["type"]];
        }
        if (!empty($params["create_at"])) {
            $between = explode(" - ", $params["create_at"]);
            if (count($between) == 2) {
                $where[] = ['create_at', '>=', $between[0]];
                $where[] = ['create_at', '<=', $between[1]];
            }
        }
        $ret =  $this->service ->getList($where);
        $this->result($ret);
    }
}